package remoteControl.activity;

import android.os.Bundle;
import android.text.InputFilter;
import android.text.InputType;
import android.text.Spanned;
import android.text.method.NumberKeyListener;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.whu.zj.R;
import com.whu.zj.UIHandler;

/**
 * 远程控制
 * Created by Administrator on 2016/3/10.
 */
public class RemoteControlActivity extends UIHandler.BaseActivity {

    Button btn_back;
    EditText et_phone;
    Button btn_send;

    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (v == btn_back)
            {
                RemoteControlActivity.this.finish();
            }
            else if (v == btn_send)
            {
                send();
            }
        }
    };

    private void send() {
        if (et_phone.getText().toString().length() != 11)
        {
            Toast.makeText(this,"电话号码位数不正确",Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_remotecontrol);
        initview();
    }

    //
    private void initview() {
        btn_back = (Button) findViewById(R.id.id_btn_back);
        btn_back.setOnClickListener(onClickListener);

        btn_send = (Button) findViewById(R.id.id_btn_send);
        btn_send.setOnClickListener(onClickListener);

        et_phone = (EditText) findViewById(R.id.id_phone);
        et_phone.setKeyListener(new NumberKeyListener() {
            @Override
            protected char[] getAcceptedChars() {
                StringBuffer sb = new StringBuffer();
                for (int i = 48; i <= 57; i++) {
                    sb.append((char) i);
                }
                return sb.toString().toCharArray();
            }

            @Override
            public int getInputType() {
                return InputType.TYPE_MASK_VARIATION;
            }
        });
    }
}
